<template>
  <div class="wx-binding"></div>
</template>
<script setup lang="ts">
  import { onMounted } from 'vue'
  import { setBindWeChat} from '@/api/wechat'
  import { useRouter,useRoute } from 'vue-router'
  const router = useRouter()
  const route = useRoute()
  onMounted(() => {
    const userName: any = route.query.userName
    const code: any = route.query.code
    if(!userName || !code) {
      return router.replace({path:'/noBinding',query:{msg1:'您暂未绑定中恒云仓客户，',msg2:'请联系公司管理员扫码绑定！'}})
    }
    bindWeChat(userName, code)
  })

  function bindWeChat(userName:string, code:string) {
    setBindWeChat({userName: userName, code: code}).then((res: any) => {
      router.replace({path:'/noBinding',query:{msg1:'已申请绑定公司，',msg2:'等待公司管理员审批!'}})
    }).catch((res: any) => {
      if(res.msg == '已绑定该账号,无需再次绑定') {
        router.replace({path:'/noBinding',query:{msg1:'已绑定该账号，',msg2:'无需再次绑定!'}})
      }
    })
  }
</script>
  